package com.yequan.thread.base.join;

public class JoinDemo2 {
    //共享变量
    public static boolean shareFlag = false;

    public static void main(String[] args) throws InterruptedException {

        Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    if (shareFlag) {
                        shareFlag = false;
                    } else {
                        shareFlag = true;
                    }
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        Thread thread2 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    if (shareFlag) {
                        System.out.println("thread2.......");
                    }
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace(); 
                }
            }
        });

        thread1.start();
        thread1.join();
        thread2.start();

    }

}
